home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / mutt / me2s_pl7.zoo / mu_edit2 / ed / lmacs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-05  |  4.1 KB  |  148 lines

  1. static char rcsid[] = "$Id: lmacs.c,v 1.1 1992/09/14 13:02:14 mike Exp $";
  2.  
  3. /* $Log: lmacs.c,v $
  4.  * Revision 1.1  1992/09/14  13:02:14  mike
  5.  * Initial revision
  6.  *
  7.  */
  8.  
  9. /* tmacs.c : the Emacs extensions to LED
  10.  * C Durland
  11.  */
  12.  
  13. /* Copyright 1990, 1991 Craig Durland
  14.  *   Distributed under the terms of the GNU General Public License.
  15.  *   Distributed "as is", without warranties of any kind, but comments,
  16.  *     suggestions and bug reports are welcome.
  17.  */
  18.  
  19. #include <char.h>
  20. #include <const.h>
  21. #include "ed.h"
  22. #include "led.h"
  23.  
  24. extern char *Ltext, *Hsearch(),    *Hcurrent(), *str_in_str();
  25. extern int Lerrorno, Lflags, Hadd(), Hprev(), Hnext();
  26. extern void Lrepeat_fcn();
  27.  
  28. extern int Ldot(), Lline_length(), Lmacs();
  29.  
  30.  
  31. #define LM_HIST_PREV    0
  32. #define LM_HIST_NEXT    1
  33. #define LM_HIST_SEARCH    2
  34. #define LM_HIST_FIRST    3
  35. #define LM_HIST_LAST    4
  36. #define LM_FOREWORD    5
  37. #define LM_BACKWORD    6
  38. #define LM_DELWORD    7
  39. #define LM_VERSION    8
  40. #define LM_ABORT    9
  41.  
  42. void Lmacskeys()
  43. {
  44.   Lregister_callback(0, Lmacs);
  45.  
  46.   Ldo_fcn(
  47.     LF_BINDKEY,
  48.       LF_ABORT,        CTRL|'G',    /* abort */
  49.       LF_RIGHT,        CTRL|'F',    /* next-character */
  50.       LF_LEFT,        CTRL|'B',    /* previous-character */
  51.       LF_BoL,        CTRL|'A',    /* beginning-of-line */
  52.       LF_DEL_CHAR,    CTRL|'D',    /* delete-character */
  53.       LF_EEoL,        CTRL|'K',    /* kill-line */
  54.       LF_EoL,        CTRL|'E',    /* end-of-line */
  55.       LF_QUOTE,        CTRL|'^',    /* quote */
  56.       LF_QUOTE,        CTRL|'Q',    /* quote - Often unreachable */
  57.  
  58. #if 0
  59.       LF_EXTEND, LM_ABORT,    CTRL|'C',
  60.       LF_EXTEND, LM_ABORT,    CTRL|'G',
  61. #endif
  62.  
  63.       LF_EXTEND, LM_FOREWORD,    META|'F',
  64.       LF_EXTEND, LM_BACKWORD,    META|'B',
  65.       LF_EXTEND, LM_DELWORD,    META|'D',
  66.       LF_EXTEND, LM_VERSION,    CTRL|'V',
  67.       LF_EXTEND, LM_HIST_NEXT,    CTRL|'N',
  68.       LF_EXTEND, LM_HIST_PREV,    CTRL|'P',
  69.       LF_EXTEND, LM_HIST_SEARCH, CTRL|'R',
  70.       LF_EXTEND, LM_HIST_FIRST, META|'<',
  71.       LF_EXTEND, LM_HIST_LAST,    META|'>',
  72.  
  73.       LF_EXTEND, LM_HIST_PREV,    SOFKEY|'C',    /* up arrow */
  74.       LF_EXTEND, LM_HIST_NEXT,    SOFKEY|'D',    /* down arrow */
  75.  
  76.       LF_STOP,
  77.  
  78.     LF_PKEY,
  79.       0,CTRL | '[', LF_STOP,
  80.     LF_STOP);
  81. }
  82.  
  83. static char *search_pattern;
  84. static int matcher(ptr) char *ptr;
  85.     { return (NULL != str_in_str(ptr, search_pattern)); }
  86.  
  87. Lmacs(kc,fcn, op) KeyCode kc; int fcn, *op;
  88. {
  89.   extern char *Hsearch();
  90.   extern int Lflags;
  91.  
  92.   char *ptr;
  93.   int n, dot = Ldot(), linelength = Lline_length();
  94.  
  95.   switch (fcn)
  96.   {
  97.     default: return FALSE;        /* nothing I know about */
  98.     case LM_FOREWORD:
  99.       while (dot < linelength &&  isspace(Ltext[dot])) dot++;
  100.       while (dot < linelength && !isspace(Ltext[dot])) dot++;
  101.       Lrepeat_fcn(LF_RIGHT,dot -Ldot());
  102.       break;
  103.     case LM_BACKWORD:
  104.       if (0 < dot) dot--;
  105.       while (0 < dot &&  isspace(Ltext[dot])) dot--;
  106.       while (0 < dot && !isspace(Ltext[dot])) dot--;
  107.       if (dot) dot++;    /* move back to start of word */
  108.       Lrepeat_fcn(LF_LEFT,Ldot() -dot);
  109.       break;
  110.     case LM_DELWORD:
  111.     break;
  112.     case LM_HIST_PREV:          /* move to previous history entry */
  113.       if (Hprev())
  114.     Ldo_fcn(LF_CLEAR_LINE,LF_INSERT_STRING,Hcurrent(),LF_STOP);
  115.       break;
  116.     case LM_HIST_NEXT:              /* move to next history entry */
  117.       if (Hnext())
  118.     Ldo_fcn(LF_CLEAR_LINE,LF_INSERT_STRING,Hcurrent(),LF_STOP);
  119.       break;
  120.     case LM_HIST_SEARCH:
  121.       n = Lflags; Lflags |= (LFnohist | LFrecdraw);
  122.       Led("Search for: ","",(pfi)NULL);
  123.       search_pattern = Ltext;
  124.       if (ptr = Hsearch(FALSE,matcher))
  125.     Ldo_fcn(LF_CLEAR_LINE,LF_INSERT_STRING,ptr,LF_STOP);
  126.       Lflags = n;
  127.       break;
  128.     case LM_HIST_FIRST:
  129.       Hbottom();
  130.       Ldo_fcn(LF_CLEAR_LINE,LF_INSERT_STRING,Hcurrent(),LF_STOP);
  131.       break;
  132.     case LM_HIST_LAST:
  133.       Htop(); Hprev();
  134.       Ldo_fcn(LF_CLEAR_LINE,LF_INSERT_STRING,Hcurrent(),LF_STOP);
  135.       break;
  136.     case LM_VERSION:
  137.       t_clearline(); printf(">LED version<"); t_flush();
  138.       Ldo_fcn(LF_REDRAW,LF_STOP);
  139.       break;
  140. /*    case LM_ABORT: Texit(); */
  141.   }
  142.   *op = LF_NOOP;
  143.  
  144.   return TRUE;
  145. }
  146.  
  147. void Lrepeat_fcn(fcn,n) { while (n--) Ldo_fcn(fcn,LF_STOP); }
  148.